package com.wskeee.ec.managers
{
	import com.wskeee.ec.core.EComponent;
	import com.wskeee.ec.logger.Logger;
	
	public class ComponentManager implements IComponentManager
	{
		/**
		 * 保存所有组件引用 
		 */
		private var components:Vector.<EComponent> = new Vector.<EComponent>();
		
		public function add(value:EComponent):void
		{
			components.push(value);
		}
		
		public function remove(value:EComponent):void
		{
			var index:int = components.indexOf(value);
			if(index!=-1)
				components.splice(index,1);
		}
		
		/**
		 * 调用所有组件 指定函数 
		 * @param value	函数名
		 * 
		 */
		public function callComponentsFun(value:String):void
		{
			for(var i:int=0,len:int=components.length;i<len;i++)
			{
				try
				{
					components[i][value]();
				} 
				catch(error:Error) 
				{
					Logger.error("callComponentsFun 出错！"+error.message);	
				}
			}
		}
	}
}